package egs.comms;

import java.io.*;
import java.nio.ByteBuffer;
import java.net.*;

import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import egs.packets.*;

public class ClientConnection extends Connection {

    /*
     * Construct a connection object to a client
     */
       
    public ClientConnection( Socket cli ) throws IOException {

        super(cli );
     }
    
    public ClientConnection (int bufSize){
    	super(bufSize);
    }
    public void connect(String host, int port) throws UnknownHostException, IOException{
    	this.socket = new Socket(host, port);
    	//this.socket.setSoTimeout(SO_TIMEOUT);
    	this.socket.setSoLinger(true, SO_TIMEOUT);
    	this.setStreams();
    	
    }
    
    public Socket secureConnect(String host, int port) throws UnknownHostException, IOException{
    	SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    	this.socket = ( SSLSocket ) socketFactory.createSocket( host, port);
    	this.socket.setSoTimeout(SO_TIMEOUT);
    	//this.socket.setSoLinger(true, SO_TIMEOUT);
    	this.setStreams();
    	
    	return this.socket;
    }
}